feat(pgpm): add slice command for modularizing migration plans#578
Merged
pyramation merged 7 commits intomainfrom Jan 27, 2026
Merged
feat(pgpm): add slice command for modularizing migration plans#578pyramation merged 7 commits intomainfrom
pyramation merged 7 commits intomainfrom
Conversation
- Add core slicing logic in pgpm/core/src/slice/ with path-based grouping - Implement folder-based strategy to extract package names from change paths - Add dependency graph building, validation, and topological sorting - Generate cross-package dependencies using package:change syntax - Add slice command to pgpm CLI with dry-run and configuration options - Include comprehensive test suite with 18 passing tests - Add detailed design specification document
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Add PatternStrategy and PatternSlice types to slice/types.ts - Implement findMatchingPattern function using minimatch for glob matching - Update assignChangesToPackages to handle 'pattern' strategy type - Update CLI to accept --strategy flag (folder or pattern) - Add --patterns flag for JSON pattern file path - Add conditional prompting (only ask for depth/prefix with folder strategy) - Add tests for pattern-based slicing functionality - Add minimatch dependency to pgpm/core This allows users to choose between: 1. Folder-based strategy: depth-based extraction from path hierarchy 2. Pattern-based strategy: glob pattern matching for flexible grouping
This test verifies that sliced packages can actually be deployed to a database: 1. Creates a plan file with changes across multiple schemas 2. Slices it into packages using folder-based and pattern-based strategies 3. Writes the packages to disk 4. Deploys each package in the computed deploy order 5. Verifies the database state (schemas, tables, cross-package deps) This ensures the slice output is valid and deployable, not just syntactically correct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(pgpm): add slice command for modularizing migration plans
Summary
Adds a new
pgpm slicecommand that partitions a large monolithic migration plan into multiple modular packages. This addresses the maintainability challenge of projects with thousands of migrations in a single package.The implementation supports two grouping strategies:
schemas/auth/tables/users→authpackage)schemas/*_auth_*/**→authpackage)Cross-package dependencies are expressed using
package:changesyntax, and the algorithm computes a valid deployment order via topological sort.Key components:
pgpm/core/src/slice/): Dependency graph building, DAG validation, package assignment, cycle detection, pattern matching via minimatchpgpm slice): Supports--strategy,--patterns,--dry-run, configurable depth/prefix, and minimum package sizepgpm/core/__tests__/slice/slice-deploy-integration.test.ts): End-to-end test that slices plans and deploys packages to a real databasedocs/spec/SLICING.md): Comprehensive documentation of the algorithm and edge casesUpdates since last revision
pgpm/MIGRATION_SLICING_SPEC.mdtodocs/spec/SLICING.mdto follow repo conventionsReview & Testing Checklist for Human
pgpm slice --dry-runagainst an actual large plan file to verify grouping and dependency detection work correctly - unit tests may not catch real-world edge casespackage:changeformat for cross-package deps - confirm this matches PGPM's expected resolution formatpgpm slice --strategy pattern --patterns ./slices.json --dry-runto verify glob matching works correctlyparsePlanFile()without errorsRecommended Test Plan
{ "slices": [ { "packageName": "auth", "patterns": ["schemas/*_auth_*/**"] }, { "packageName": "users", "patterns": ["schemas/*_users_*/**"] } ] }--dry-runand inspect the generated packages directorypgpm.planfile is valid and deployableNotes
extensions/*andmigrate/*paths are automatically assigned tocorepackageDevin run: https://app.devin.ai/sessions/84604c65fadd4983a065f855e6c82533
Previous session: https://app.devin.ai/sessions/e11be896d4dd45aaa746d1e2c42c186a
Requested by: @pyramation